package LeetCode;

import java.util.Stack;

/**
 * @Author Kechelle
 * @Date 2020/9/16 10:24
 * @Version 1.0
 */
public class Code20 {
    public static boolean isValid(String s) {
        if(s.length()%2!=0) return false;
        Stack<Character> stack = new Stack<>();
        for (char c:s.toCharArray()){
            if (c == '(') stack.push(')');
            else if (c == '{') stack.push('}');
            else if (c == '[') stack.push(']');
            else if (stack.empty() || c != stack.pop())
                return false;
        }
        //最后栈不为空则不满足
        return stack.empty();
    }

    public static void main(String[] args) {
        String s = "()[]";
        System.out.println(Code20.isValid(s));
    }
}
